const Koa = require('koa');
// 解析post请求
const bodyParser = require('koa-bodyparser');
// 解决跨域
const cors = require('koa2-cors');
// 静态文件
const static = require('koa-static');
const bouncer = require('koa-bouncer');
const session = require('koa-session');
// 路由
const {student, common} = require('./router');

const app = new Koa();

// 对cookie进行加密签名
app.keys = ['some secret hurr'];
// 对session进行配置，了解
const CONFIG = {
    key: 'sid',
    maxAge: 86400000, // sid的有效期，默认是1天
    overwrite: true,
    httpOnly: true, // 仅仅是服务器端修改cookie
    signed: true, // 签名cookie
    rolling: true, // 在每次请求时强行设置cookie，默认是false
    renew: false, // 每次请求都重新设置cookie，默认是false
}
app.use(session(CONFIG, app));

app.use(cors());
app.use(bouncer.middleware());
app.use(bodyParser());

app.use(
  static(__dirname + '/public')
);

app.use(common.routes());
app.use(student.routes());

app.listen(8080, () => {
  console.log('server is running on port 8080');
});